<?php
$path = 1;
require_once("../api.php");
session_start();
$db = new SQLite3('../chatroom.db');//连接数据库
$phone = $_POST['phone'];
$nickname = $_POST['nickname'];
$password = $_POST['password'];
$sex = $_POST['sex'];
$motto = '';
$path = "img/icon/1.jpg";
$sql =
    "select * from user where phone = '$phone'";
//输出查询结果
$result = $db->query($sql);
if( $row = $result -> fetchArray(SQLITE3_ASSOC) ){//已经有人注册过
    ajaxJSON( false, "user_exist" ,$row);
}
else{
    $sql = "insert into user (user_id, phone, password, nickname, sex, icon_path, motto, online ) values(NULL, '$phone', '$password', '$nickname', '$sex', '$path','$motto', 1 )";
    $db -> exec($sql);
    $sql =
        "select * from user where phone = '$phone'";
    $result = $db->query($sql);
    $row = $result -> fetchArray(SQLITE3_ASSOC);
    $_SESSION['user'] = array('user_id' =>$row['user_id'],
        'nickName' =>$row['nickname'],
        'iconPath' => $row['icon_path'],
        'sex' => $row['sex']
    );
    ajaxJSON( true, "success" );
}
